package com.example.mapping.controller;

import com.example.mapping.domain.ColumnMetadata;
import com.example.mapping.domain.TableMetadata;
import com.example.mapping.manage.TableManage;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 表controller类
 *
 * @author baoyoujia
 */
@RestController
public class TableController {

    private final TableManage tableManage;

    public TableController(TableManage tableManage) {
        this.tableManage = tableManage;
    }

    /**
     * 获取表
     *
     * @return
     */
    @GetMapping("/table")
    public List<TableMetadata> getTableMetadata() {
        return tableManage.getTableMetadata();
    }

    /**
     * 获取指定表的列
     *
     * @param tableName 表名
     * @return
     */
    @GetMapping("/{tableName}/column")
    public List<ColumnMetadata> getColumnMetadata(@PathVariable("tableName") String tableName) {
        return tableManage.getColumnMetadata(tableName);
    }
}
